package com.djbx.points.member.api.client;

import com.djbx.points.common.client.utils.DefaultFallbackFactory;
import com.djbx.points.common.core.utils.ServiceResponse;
import com.djbx.points.member.api.dto.MemberInDTO;
import com.djbx.points.member.api.dto.MemberOutDTO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * 优惠券信息
 *
 * @author aliuql
 * @email 17701057157@qq.com
 * @date 2021-11-15 14:31:25
 */
@FeignClient(value = "points-member", path = "/member", fallbackFactory = MemberClient.MemberClientFallbackFactory.class, decode404 = true)
public interface MemberClient {

    /**
     * 获取明细列表
     */
    @GetMapping("/get")
    ServiceResponse<MemberOutDTO> get(@RequestParam("id") Long id);

    /**
     * 获取明细列表
     */
    @GetMapping("/getList")
    ServiceResponse<MemberOutDTO> getList(@RequestBody MemberInDTO couponInDTO);

    /**
     * 获取明细列表(分页)
     */
    @GetMapping("/getPage")
    ServiceResponse<MemberOutDTO> getPage(@RequestBody MemberInDTO couponInDTO);

    /**
     * 保存
     */
    @PostMapping("/save")
    ServiceResponse<Void> save(@RequestBody MemberInDTO member);

    /**
     * 保存
     */
    @PostMapping("/update")
    ServiceResponse<Void> update(@RequestBody MemberInDTO member);

    /**
     * 保存
     */
    @PostMapping("/delete")
    ServiceResponse<Void> save(@RequestParam("id") Long id);

    /**
     * 服务降级实现类
     */
    @Component
    @Slf4j
    class MemberClientFallbackFactory implements FallbackFactory<MemberClient> {

        @Override
        public MemberClient create(Throwable cause) {
            return DefaultFallbackFactory.getFallback(MemberClient.class);
        }
    }
}
